<template>
  <div class="orderContent flex flex_column">
    <div v-for="(item, index) in productList" :key="index" class="tagList">
      <div class="listNav flex flex_between">
        <div>
          <span class="pointer" @click="shrink(item)">
            <i v-if="item.isShow" class="el-icon-arrow-down" />
            <i v-else class="el-icon-arrow-up" />
          </span>
          <span class="f16 ml15 fw">{{ item.produceTaskBillNo }}</span>
          <span class="f14 ml15">单据类型: {{ item.produceBillTypeName }}</span>
          <span
            class="f14 ml15"
          >生产状态: {{ item.produceBillStateName }}</span>
          <span class="f14 ml15">创建时间: {{ item.createDate }}</span>
          <span class="f14 ml15">创建人员: {{ item.createPersonName }}</span>
        </div>
      </div>
      <div v-if="item.isShow">
        <div
          v-for="(item2, index2) in item.craftTaskList"
          :key="index2"
          class="fileTable"
        >
          <div class="lNavt flex flex_between">
            <div class="itemCon">
              <span
                class="pointer listItem"
                :class="defclassName(item2.craftTaskState)"
                @click="shrink(item2)"
              >
                <i v-if="item2.isShow" class="el-icon-arrow-down" />
                <i v-else class="el-icon-arrow-up" />
              </span>
              <div>
                <div>
                  <span class="f16 ml15 fw">{{ item2.produceCraftName }}</span>
                </div>
                <div>
                  <span
                    class="f12 ml15"
                  >生产设备: {{ item2.produceEquipmentName }}</span>
                  <span
                    class="f12 ml15"
                  >计划工时: {{ item2.craftTaskPlanUseTime }} 分钟</span>
                  <span
                    class="f12 ml15"
                  >任务状态: {{ item2.craftTaskStateName }}</span>
                </div>
              </div>
            </div>
          </div>
          <div v-show="item2.isShow">
            <div
              v-for="(item3, index3) in item2.workTaskList"
              :key="index3"
              class="fileTable3"
            >
              <div class="listNav3 flex flex_between">
                <div>
                  <span class="pointer" @click="shrink(item3)">
                    <i v-if="item3.isShow" class="el-icon-arrow-down" />
                    <i v-else class="el-icon-arrow-up" />
                  </span>
                  <span class="f16 ml15 fw">{{ item3.workTaskNo }}</span>
                </div>
              </div>
              <div v-show="item3.isShow" class="border lastTdNoBorder w100s">
                <div class="Cmain w100">
                  <el-row :gutter="20" class="Cinfo w100">
                    <el-col :span="5">
                      <div>
                        <span class="mr15">生产人员</span>
                        {{
                          item3.workPersonName?item3.workPersonName : "--"
                        }}
                      </div>
                    </el-col>
                    <el-col :span="5">
                      <div>
                        <span class="mr15">班次</span>
                        {{
                          item3.workShiftName?item3.workShiftName : "--"
                        }}
                      </div>
                    </el-col>
                    <el-col :span="5">
                      <div>
                        <span class="mr15">开始时间</span>{{
                          item3.workBeginTime?item3.workBeginTime : "--"
                        }}
                      </div>
                    </el-col>
                    <el-col :span="5">
                      <div>
                        <span class="mr15">结束时间</span>{{
                          item3.workFinishTime?item3.workFinishTime : "--"
                        }}
                      </div>
                    </el-col>
                    <el-col :span="4">
                      <div>
                        <span class="mr15">产品耗时</span>{{
                          item3.taskUseTime ||"--"
                        }}
                      </div>
                    </el-col>
                    <el-col :span="5">
                      <div>
                        <span class="mr15">实际工时</span>{{
                          item3.actualWorkTime?item3.actualWorkTime : "--"
                        }}
                      </div>
                    </el-col>
                    <el-col :span="5">
                      <div>
                        <span class="mr15">副手人员</span>{{ formatList(item3.assistantList) }}
                      </div>
                    </el-col>
                    <el-col :span="5">
                      <div>
                        <span class="mr15">作业备注</span>{{
                          item3.workTaskRemark?item3.workTaskRemark : "--"
                        }}
                      </div>
                    </el-col>
                  </el-row>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

    </div>
    <!-- 完成机台作业   -->
    <el-dialog
      :title="Matitle"
      :visible.sync="showAddDialog"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog bigDialogh85"
      width="85%"
      @close="closeDialog"
    >
      <div class="dialogDody">
        <div class="subTip">
          <span
            class="mr15"
          ><span class="mr5">作业单号：</span>{{ machiaForm.workTaskNo || "系统自动生成" }}</span>
          <span
            class="mr15"
          ><span class="mr5">创建日期：</span>{{
            machiaForm.workBeginTime || dayjs().format("YYYY-MM-DD")
          }}</span>
          <span><span class="mr5">创建人员：</span>{{
            machiaForm.billCreateBy ? machiaForm.workPersonName : name
          }}</span>
        </div>
        <el-form
          ref="machiaForm"
          :model="machiaForm"
          class="dialogForm h100"
          label-width="80px"
        >
          <el-row class="h100">
            <el-col :span="18" class="fleft h100">
              <el-row>
                <el-col
                  :span="8"
                ><el-form-item label="工艺名称" prop="produceCraftName">
                  <el-input
                    v-model="machiaForm.produceCraftName"
                    size="mini"
                    :disabled="canDisablle"
                  /> </el-form-item></el-col>
                <el-col
                  :span="8"
                ><el-form-item label="订单单号" prop="saleOrderNo">
                  <el-input
                    v-model="machiaForm.xieYiShuHao"
                    size="mini"
                    :disabled="canDisablle"
                  /></el-form-item></el-col>
                <el-col
                  :span="8"
                ><el-form-item label="产品名称" prop="orderProductName">
                  <el-input
                    v-model="machiaForm.orderProductName"
                    size="mini"
                    :disabled="canDisablle"
                  /></el-form-item></el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="生产设备" prop="equipmentName">
                    <el-input
                      v-model="machiaForm.equipmentName"
                      size="mini"
                      :disabled="canDisablle"
                    /> </el-form-item></el-col>
                <el-col :span="16">
                  <el-form-item label="副手人员" prop="assistantList">
                    <div class="flex permain">
                      <div class="input">
                        <span
                          v-for="(v, p) in assisList	"
                          :key="v.employeeCode"
                          class="pointer"
                          @click="deletrPer(p)"
                        >
                          {{ v.employeeName }}<i class="el-icon-close" />
                        </span>
                      </div>
                      <el-button
                        class="bgc57"
                        size="mini"
                        icon="el-icon-user"
                        @click=" openPer "
                      />
                    </div>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="作业备注" prop="workTaskRemark">
                    <el-input
                      v-model="machiaForm.workTaskRemark"
                      size="mini"
                      :disabled="allcanDisablle"
                    /> </el-form-item></el-col>
              </el-row>
              <div class="cTitle">
                <h3>作业信息</h3>
                <el-row>
                  <el-col
                    :span="8"
                  ><el-form-item label="开始码段" prop="beginNumberSegment">
                    <el-input
                      v-model="machiaForm.beginNumberSegment"
                      size="mini"
                      :disabled="allcanDisablle"
                    /> </el-form-item></el-col>
                  <el-col
                    :span="8"
                  ><el-form-item label="结束码段" prop="endNumberSegment">
                    <el-input
                      v-model="machiaForm.endNumberSegment"
                      size="mini"
                      :disabled="allcanDisablle"
                    /></el-form-item></el-col>
                  <el-col
                    :span="8"
                  ><el-form-item label="完成卷数" prop="finishedRollCount">
                    <el-input
                      v-model="machiaForm.finishedRollCount"
                      size="mini"
                      :disabled="allcanDisablle"
                    > <template slot="append">卷</template></el-input></el-form-item></el-col>
                </el-row>
                <el-row>
                  <el-col
                    :span="8"
                  ><el-form-item label="成品米数" prop="productMeter">
                    <el-input
                      v-model="machiaForm.productMeters"
                      disabled
                      size="mini"
                    > <template slot="append">米</template></el-input> </el-form-item></el-col>

                  <el-col
                    :span="8"
                  ><el-form-item label="完成米数" prop="finishedMeters">
                    <el-input
                      v-model="machiaForm.finishedMeters"
                      onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                      size="mini"
                      :disabled="allcanDisablle"
                      @blur="productMeter"
                    > <template slot="append">米</template></el-input> </el-form-item></el-col>

                  <el-col
                    :span="8"
                  ><el-form-item label="报废米数" prop="scrapMeters">
                    <el-input
                      v-model="machiaForm.scrapMeters"
                      onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                      size="mini"
                      :disabled="allcanDisablle"
                      @blur="productMeter"
                    > <template slot="append">米</template></el-input> </el-form-item></el-col>
                </el-row>
                <div class="tableBox">
                  <div class="tt flex flex_between">
                    <span class="fw">异常明细</span>
                    <span v-show="!allcanDisablle" class="c_3F61F1 mr15 pointer" @click="addExecp"><i class="el-icon-plus mr5" /> 新增</span>
                  </div>
                  <div ref="bigdialogTable" class="bigdialogTbCon">
                    <el-table
                      :data="machiaForm.exceptionDataList"
                      border
                      style="width: 100%"
                    >
                      <el-table-column
                        type="index"
                        label="序号"
                        width="100"
                      />
                      <el-table-column
                        label="异常码段"
                        prop="applyGetQuantity"
                        show-overflow-tooltip
                        width="190"
                      >         <template slot-scope="{row}">
                        <el-input
                          v-model="row.exceptionNumberSegment"
                          placeholder="请输入"
                          size="mini"
                          :disabled="allcanDisablle"
                        />
                      </template>
                      </el-table-column>
                      <el-table-column
                        label="异常类型"
                        prop="applyGetQuantity"
                        show-overflow-tooltip
                        width="190"
                      >         <template slot-scope="{row}">
                        <el-select
                        filterable v-model="row.exceptionType" placeholder="请选择" size="mini" :disabled="allcanDisablle">
                          <el-option
                            v-for="item in ExceptionTypeList"
                            :key="item.objectCode"
                            :label="item.objectName"
                            :value="item.objectCode"
                          />
                        </el-select>
                      </template>
                      </el-table-column>

                      <el-table-column
                        label="异常原因"
                        show-overflow-tooltip
                        min-width="150"
                        prop="getMaterialRemark"
                      >
                        <template slot-scope="{row}">
                          <el-input v-model="row.exceptionReason" placeholder="请输入" size="mini" :disabled="allcanDisablle" />
                        </template>
                      </el-table-column>
                      <el-table-column
                        v-if="!allcanDisablle"
                        label="操作"
                        fixed="right"
                        min-width="80"
                        align="center"
                      >
                        <template slot-scope="scope">
                          <el-tooltip class="item" effect="dark" content="删除" placement="right-start">
                            <span class="pointer" @click="deleteRow(scope.$index)">删除</span>
                          </el-tooltip>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </div>
            </el-col>
            <el-col :span="6" class="formItem fright">
              <el-form-item label="上班班次" prop="indexNumber">
                <el-select
                        filterable v-model="machiaForm.workShiftNo" :disabled="allcanDisablle" placeholder="请选择" size="mini" @change="changeOrg">
                  <el-option
                    v-for="item in bcList"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="开始时间">
                <el-date-picker
                  v-model="machiaForm.workBeginTime"
                  type="datetime"
                  :picker-options="option"
                  placeholder="选择日期"
                  size="mini"
                  :disabled="canDisablle"
                />
              </el-form-item>
              <el-form-item label="结束时间">
                <el-date-picker
                  v-model="machiaForm.workFinishTime"
                  type="datetime"
                  :picker-options="option"
                  placeholder="选择日期"
                  size="mini"
                  :disabled="canDisablle"
                />
              </el-form-item>
              <el-form-item label="产品耗时">
                <el-input
                  v-model="machiaForm.produceUseTime"
                  onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                  placeholder="0"
                  size="mini"
                  :disabled="canDisablle"
                >
                  <template slot="append">分钟</template></el-input>
              </el-form-item>
              <el-form-item label="调机时间">
                <el-input
                  v-model="machiaForm.debugMachineTime"
                  onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                  placeholder="0"
                  size="mini"
                  :disabled="allcanDisablle"
                  @blur="getChangeTime"
                >
                  <template slot="append">分钟</template></el-input>
              </el-form-item>
              <el-form-item label="辅助时间">
                <el-input
                  v-model="machiaForm.assistTime"
                  onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                  placeholder="0"
                  size="mini"
                  :disabled="allcanDisablle"
                  @blur="getChangeTime"
                >
                  <template slot="append">分钟</template></el-input>
              </el-form-item>
              <el-form-item label="待机时间">
                <el-input
                  v-model="machiaForm.standbyTime"
                  onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                  placeholder="0"
                  size="mini"
                  :disabled="allcanDisablle"
                  @blur="getChangeTime"
                >
                  <template slot="append">分钟</template></el-input>
              </el-form-item>
              <el-form-item label="维修时间">
                <el-input
                  v-model="machiaForm.maintainTime"
                  onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                  placeholder="0"
                  size="mini"
                  :disabled="allcanDisablle"
                  @blur="getChangeTime"
                >
                  <template slot="append">分钟</template></el-input>
              </el-form-item>

              <el-form-item label="吃饭次数">
                <el-row class="flex" :gutter="10">
                  <el-col :span="8">
                    <el-input
                      v-model="machiaForm.eatCount"
                      onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                      placeholder="0"
                      size="mini"
                      :disabled="allcanDisablle"
                      @blur="getChangeTime"
                    />
                  </el-col>
                  <el-col :span="16">
                    <el-input
                      v-model="machiaForm.eatUseSumTime"
                      onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                      placeholder="0"
                      size="mini"
                      disabled
                    >
                      <template slot="append">分钟</template></el-input>
                  </el-col>
                </el-row>
              </el-form-item>
              <el-form-item label="晒版次数">
                <el-row class="flex" :gutter="10">
                  <el-col :span="8">
                    <el-input
                      v-model="machiaForm.printingDownCount"
                      onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                      placeholder="0"
                      size="mini"
                      :disabled="allcanDisablle"
                      @blur="getChangeTime"
                    />
                  </el-col>
                  <el-col :span="16">
                    <el-input
                      v-model="machiaForm.printingDownSumTime"
                      onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                      placeholder="0"
                      size="mini"
                      disabled
                    >
                      <template slot="append">分钟</template></el-input>
                  </el-col>
                </el-row>
              </el-form-item>
              <el-form-item label="开会次数">
                <el-row class="flex" :gutter="10">
                  <el-col :span="8">
                    <el-input
                      v-model="machiaForm.meetingCount"
                      onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                      placeholder="0"
                      size="mini"
                      :disabled="allcanDisablle"
                      @blur="getChangeTime"
                    />
                  </el-col>
                  <el-col :span="16">
                    <el-input
                      v-model="machiaForm.meetingSumTime"
                      onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                      placeholder="0"
                      size="mini"
                      disabled
                    >
                      <template slot="append">分钟</template></el-input>
                  </el-col>
                </el-row>
              </el-form-item>
              <el-form-item label="实际工时">
                <el-input
                  v-model="machiaForm.actualWorkTime"
                  onkeyup="this.value = this.value.replace(/[^\d.]/g,'');"
                  placeholder="0"
                  size="mini"
                  disabled
                >
                  <template slot="append">分钟</template></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          size="mini"
          @click="showAddDialog = false"
        >取 消</el-button>
        <!-- 新增       -->
        <el-button
          v-if="opsid !== -1"
          :loading="addLoading"
          :disabled="addLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveMachina"
        >
          {{ opsid === 0 ? "完成" : "保存" }}</el-button>
      </div>
    </el-dialog>
    <!-- 人员寻找弹框   -->
    <per-redio-dialog
      :per-visible.sync="isperShow"
      @getEmployee="getEmployee"
    />
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import perRedioDialog from '@/components/perDialogRedio'
import { formatbytes, parseTime } from '@/utils'
export default {
  name: '',
  components: { perRedioDialog },
  props: {
    orderNo: {
      type: String
    }
  },
  data() {
    return {
      opsid: 0,
      showAddDialog: false,
      ExceptionTypeList: [],
      isperShow: false,
      machiaForm: {
        scrapMeters: 0,
        finishedMeters: 0,
        productMeters: 0,
        exceptionDataList: []
      },
      saleOrderID: '',
      saleOrderNo: '',
      Matitle: '',
      option: {
        disabledDate: (time) => {
          return time.getTime() < Date.now() - 1 * 24 * 3600 * 1000
        }
      },
      assisList: [],
      bcList: [],
      canDisablle: false,
      allcanDisablle: false,
      addLoading: false,
      ops: [],
      showTOP: false,
      productList: []
    }
  },
  computed: {
    ...mapGetters(['name'])

  },
  created() {
    this.saleOrderID = this.$route.query.saleOrderID
    this.saleOrderNo = this.$route.query.saleOrderNo
    this.showTOP = this.$route.query.showTOP
    this.getList()
    this.getBC()
    this.getWorkExceptionTypeDataList()
  },
  mounted() {},
  methods: {

    getWorkExceptionTypeDataList() {
      this.$api.system.GetWorkExceptionTypeDataList({}).then((res) => {
        this.ExceptionTypeList = res
      })
    },
    addExecp() {
      this.machiaForm.exceptionDataList.push({
        exceptionNumberSegment: '',
        exceptionType: this.ExceptionTypeList[0].exceptionType,
        exceptionReason: ''
      })
    },
    deleteRow(index) {
      this.machiaForm.exceptionDataList.splice(index, 1)
    },
    parseTime(time, cFormat) {
      return parseTime(time, cFormat)
    },
    timeFn(d1, d2) {
      if (d1 && d2) {
      // 如果时间格式是正确的，那下面这一步转化时间格式就可以不用了
        const dateBegin = new Date(d1.replace(/-/g, '/'))// 将-转化为/，使用new Date
        const dateEnd = new Date(d2.replace(/-/g, '/'))// 获取当前时间
        const dateDiff = dateEnd.getTime() - dateBegin.getTime()// 时间差的毫秒数
        const leave1 = dateDiff % (24 * 3600 * 1000) // 计算天数后剩余的毫秒数
        // 计算相差分钟数
        const leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
        const minutes = Math.floor(leave1 / (60 * 1000))// 计算相差分钟数
        return minutes
      }
    },
    productMeter() {
      this.machiaForm.productMeters = Number(this.machiaForm.scrapMeters) + Number(this.machiaForm.finishedMeters)
    },
    getChangeTime() {
      this.machiaForm.meetingSumTime = Number(this.machiaForm.meetingCount) * 30
      this.machiaForm.printingDownSumTime = Number(this.machiaForm.printingDownCount) * 30
      this.machiaForm.eatUseSumTime = Number(this.machiaForm.eatCount) * 30
      this.machiaForm.actualWorkTime = this.machiaForm.produceUseTime - (this.machiaForm.eatUseSumTime + this.machiaForm.printingDownSumTime +
      this.machiaForm.meetingSumTime + Number(this.machiaForm.maintainTime) + Number(this.machiaForm.standbyTime) +
      Number(this.machiaForm.assistTime) + Number(this.machiaForm.debugMachineTime))
    },
    shrink(item) {
      this.$set(item, 'isShow', !item.isShow)
    },
    BCPLL(item) {
      this.$router.push({
        path: '/production/productionPicker/semiFinishProduct', // 跳转的路径
        query: {
          openADD: true,
          item: item
        }
      })
    },
    formatList(list){
      let arr = []
       list.forEach((item)=>{
        arr.push(item.employeeName)
      })
      return arr.join(',')
    },

    CSLL(item) {
      this.$router.push({
        path: '/production/productionPicker/finishProduct', // 跳转的路径
        query: {
          openADD: true,
          item: item
        }
      })
    },
    SCTL(item) {
      this.$router.push({
        path: '/production/productionScrapSheet', // 跳转的路径
        query: {
          openADD: true,
          item: item
        }
      })
    },
    changeOrg() {

    },
    getBC() {
      const _d = {
        isDelete: 0,
        isDisable: 0,
        likeWords: '',
        pageIndex: 1,
        pageSize: 30
      }

      this.$api.system.GetMatchPageProductClasss(_d).then((res) => {
        this.bcList = res.list
      })
    },
    defclassName(c) {
      if (c === 0) {
        return 'wait'
      } else if (c === 1) {
        return 'product'
      } else {
        return 'down'
      }
    },
    // 新建
    productCopy(item2, index2, index) {
      let state = false
      for (let work = 0; work < item2.workTaskList.length; work++) {
        if (item2.workTaskList[work].craftWorkState !== 1) {
          this.$confirm('还有未完成的作业，是否新建', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            const { saleOrderNo, produceTaskBillNo, craftTaskNo } = item2
            this.$api.product.CreateProduceCraftWorkTask({
              saleOrderNo: saleOrderNo,
              produceTaskBillNo: produceTaskBillNo,
              craftTaskNo: craftTaskNo
            }).then((res) => {
              this.$message({
                type: 'success',
                message: '新建成功!'
              })
              this.getList()
              // this.setSCZY(item2, index2, index)
            })
          })
          break
        } else {
          state = true
        }
      }
      if (state || item2.workTaskList.length === 0) {
        const { saleOrderNo, produceTaskBillNo, craftTaskNo } = item2
        this.$api.product.CreateProduceCraftWorkTask({
          saleOrderNo: saleOrderNo,
          produceTaskBillNo: produceTaskBillNo,
          craftTaskNo: craftTaskNo
        }).then((res) => {
          this.$message({
            type: 'success',
            message: '新建成功!'
          })
          this.getList()
        // this.setSCZY(item2, index2, index)
        })
      }
    },
    setSCZY(item2, index2, index) {
      const _data = {
        saleOrderNo: this.orderNo
      }
      this.$api.product.GetProduceCraftWorkTasksForOrder(_data).then((res) => {
        const _dd = res[index].craftTaskList[index2].workTaskList[0]
        _dd.workTaskNo = res[index].craftTaskList[index2].workTaskList[0].workTaskNo + Math.floor(Math.random(0, 1) * 10)
        // item2.workTaskList = res[index].craftTaskList[index2].workTaskList[0]
        item2.workTaskList.push(_dd)
        // this.productList = res
      })
    },
    saveMachina() {
      const _d = []
      this.assisList.forEach(e => {
        _d.push(e.employeeCode)
      })
      this.machiaForm.assistantList = _d
      if (this.opsid === 0) {
        this.$confirm('完成后不可修改，是否完成', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.product.FinishedProduceCraftWorkTask(this.machiaForm).then((res) => {
            this.getList()
            this.$message({
              type: 'success',
              message: '完成成功!'
            })
            this.showAddDialog = false
          })
        })
      } else {
        this.$api.product.UpdateProduceCraftWorkTask(this.machiaForm).then((res) => {
          this.getList()
          this.$message({
            type: 'success',
            message: '修改成功!'
          })
          this.showAddDialog = false
        })
      }
    },
    openPer() {
      if (this.allcanDisablle) {
        return
      } else {
        this.isperShow = true
      }
    },
    closeDialog() {},
    getList() {
      const _data = {
        saleOrderNo: this.saleOrderNo ? this.saleOrderNo : this.orderNo,
        produceBillType: 0,
        produceBillState: -1,
        taskProduceState: -1,
        craftWorkState: -1
      }
      this.$api.product.GetProduceCraftWorkTasksForOrder(_data).then((res) => {
        res.forEach(e => {
          e.craftTaskList.forEach(e2 => {
            e2.workTaskList.forEach(e3 => {
              this.$set(e3, 'isShow', true)
            })
            this.$set(e2, 'isShow', true)
          })
          this.$set(e, 'isShow', true)
        })
        this.productList = res
      })
    },
    stopOne(item3) {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$api.product
          .DeleteProduceCraftWorkTask({
            workTaskID: item3.workTaskID
          })
          .then((res) => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getList()
          })
          .catch(() => {
          })
      })
    },
    checkWork(item3) {
      this.opsid = -1
      this.Matitle = '查看生产作业'
      this.canDisablle = true
      this.allcanDisablle = true
      const _data = {
        workTaskID: item3.workTaskID,
        workTaskNo: item3.workTaskNo
      }
      this.$api.product.GetProduceCraftWorkTaskDetail(_data).then((res) => {
        this.assisList	 = res.assistantList
        this.machiaForm = res.baseData
        this.machiaForm.exceptionDataList = res.exceptionDataList
        this.machiaForm.produceUseTime = this.timeFn(this.machiaForm.workBeginTime, this.machiaForm.workFinishTime)
        // this.machiaForm.workShiftNo = 'BC0019'
        this.showAddDialog = true
      })
    },
    print(item3) {
      this.opsid = 2
      this.Matitle = '修改生产作业'
      this.canDisablle = true
      this.allcanDisablle = false
      const _data = {
        workTaskID: item3.workTaskID,
        workTaskNo: item3.workTaskNo
      }
      this.$api.product.GetProduceCraftWorkTaskDetail(_data).then((res) => {
        this.assisList	 = res.assistantList
        this.assisList.forEach(e => {
          e.employeeCode = e.employeeNo
        })
        this.machiaForm = res.baseData
        this.machiaForm.exceptionDataList = res.exceptionDataList
        this.machiaForm.produceUseTime = this.timeFn(this.machiaForm.workBeginTime, this.machiaForm.workFinishTime)
        // this.machiaForm.workShiftNo = 'BC0019'
        this.showAddDialog = true
      })
    },
    doneWork(item3) {
      this.opsid = 0
      this.Matitle = '完成生产作业'
      this.canDisablle = true
      this.allcanDisablle = false
      const _data = {
        workTaskID: item3.workTaskID,
        workTaskNo: item3.workTaskNo
      }
      this.$api.product.GetProduceCraftWorkTaskDetail(_data).then((res) => {
        this.assisList	 = res.assistantList
        this.assisList.forEach(e => {
          e.employeeCode = e.employeeNo
        })
        this.machiaForm = res.baseData
        this.machiaForm.exceptionDataList = res.exceptionDataList
        this.machiaForm.workFinishTime = this.parseTime(new Date())// 获取当前时间
        this.machiaForm.produceUseTime = this.timeFn(this.machiaForm.workBeginTime, this.machiaForm.workFinishTime)
        // this.machiaForm.workShiftNo = 'BC0019'
        this.showAddDialog = true
      })
    },
    deletrPer(index) {
      if (this.allcanDisablle) {
        return
      } else {
        this.assisList.splice(index, 1)
      }
    },
    // 得到申请人员
    getEmployee(val) {
      //  this.contractForm.contractSigningPerson = val.employeeCode
      // this.contractForm.contractSigningPersonName = val.employeeName

      if (this.assisList.length === 0) {
        this.assisList.push({
          employeeCode: val.employeeCode,
          employeeName: val.employeeName
        })
      } else {
        const checked = this.assisList.some((item) => {
          if (item.employeeCode === val.employeeCode) {
            return true
          }
        })
        if (!checked) {
          this.assisList.push({
            employeeCode: val.employeeCode,
            employeeName: val.employeeName
          })
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}

::v-deep .formItem {
  .el-form-item {
    margin-bottom: 0;
    color: #999aaa;
  }
  .min_item .el-form-item__label {
    line-height: 35px;
    color: #999aaa;
  }
  .min_item .el-form-item__content {
    line-height: 35px;
  }
  .el-form-item__label {
    line-height: 35px;
    color: #999aaa;
  }

  .el-form-item__content {
    line-height: 35px;

    .el-input-group {
      vertical-align: initial;
    }
  }

  .el-select,
  .el-date-editor.el-input {
    width: 100%;
  }

  .el-textarea {
    vertical-align: middle;
  }
}

::v-deep .selectdd {
  .el-input__inner {
    line-height: 30px;
    border-radius: 4px 0px 0px 4px;
  }
  .el-input__suffix {
    display: none;
  }
}

.permain {
  // align-items: baseline;
  line-height: 40px;
  height: 40px;
  .input {
        // background: #F5F7FA;
    width: 100%;
    height: 28px;
    line-height: 28px;
    border-radius: 4px 0 0 4px;
    border: 1px solid #dcdfe6;
    span {
      display: inline-block;
      font-size: 12px;
      height: 22px;
      line-height: 22px;
      padding: 2px 5px;
      background-color: #f5f6f9;
      margin: 2px 5px;
    }
  }
  .bgc57 {
    height: 28px;
    background-color: #f5f7fa;
    border-radius: 0px 4px 4px 0px;
  }
}

.fleft {
  border-right: 1px solid #d8d8d8;
  padding: 16px;
}
.fright {
  padding: 16px;
  .count {
    display: flex;
    align-items: center;
    color: #999AAA;
  }
}
.subTip {
  border-bottom: 1px #e6e6e6 solid;
  background: #f5f6f9;
  padding: 8px 16px;
}

.lNavt {
  height: 52px;
  padding-right: 4px;
  background: #f5f6f9;
  border-bottom: 1px solid #e6e6e6;
  .itemCon {
    height: 100%;
    display: flex;
    align-items: center;
    .listItem {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 52px;
      width: 52px;
      color: #f5f7fa;
      &.wait {
        color: #666;
        background-color: #E4E7F0;
      }
      &.product {
        background-color: #3f61f1;
      }
      &.down {
        background-color: #6bc53f;
      }
    }
  }
}

.tableBox {
    margin-top: 16px;
    border: 1px solid #e6e6e6;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    overflow: hidden;

    .tt {
      height: 38px;
      line-height: 38px;
      padding-left: 16px;
      background: #f7f8fa;
      border-radius: 8px 8px 0 0;
    }
  }
.Cmain {
  .Cinfo {
    color: #999aaa;
    padding: 10px;
    div {
      line-height: 28px;
    }
  }
}
.orderContent {
  width: 100%;
  flex: 1;
}
.tagList {
  box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.05);
  border: 1px solid #e6e6e6;
  margin-bottom: 16px;
  width: 100%;
  .listNav {
    height: 44px;
    padding: 0 14px;
    background: #f5f6f9;
    border-bottom: 1px solid #e6e6e6;
  }
  .listNav3 {
    height: 44px;
    padding: 0 4px 0 14px;
    background: #f5f6f9;
    border-bottom: 1px solid #e6e6e6;
  }

  .fileTable {
    padding: 10px;
    .border {
      border: solid #ebeef5;
      border-width: 0 1px 0 1px;
    }
  }
  .fileTable3 {
    padding: 10px 0 0 0;
    .border {
      border: solid #ebeef5;
      border-width: 1px 1px 1px 1px;
    }
  }
}

</style>
